package com.sdry.web.controller.cb;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.model.cb.DepreciationEntity;
import com.sdry.model.cb.TableDataInfo;
import com.sdry.model.lz.Warehouse;
import com.sdry.service.cb.DepreciationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 折旧费用
 */
@Controller
@RequestMapping("depreciation")
public class DepreciationController extends BaseController{

    @Autowired
    private DepreciationService depreciationService;

    @RequestMapping()
    public String index(Model model) {
        //仓库
        List<Warehouse> warehouseList = iDicMapper.getWarehouseList();
        model.addAttribute("warehouseList",warehouseList);
        return "/cb/depreciation";
    }

    @RequestMapping("/addPage")
    public String addPage() {

        return "/cb/add";
    }

    @RequestMapping("list")
    @ResponseBody
    public TableDataInfo getList(
            @RequestParam("page") Integer page ,
            @RequestParam("pageSize") Integer pageSize
    ) {

        DepreciationEntity de = new DepreciationEntity();
        PageHelper.startPage(page,pageSize);
        List<DepreciationEntity> list = depreciationService.getList(de);
        PageInfo pageInfo = new PageInfo(list,5);
        return getDataTable(pageInfo.getList(),Math.toIntExact(pageInfo.getTotal()));
    }

    @RequestMapping("/add")
    @ResponseBody
    public Integer add(
           DepreciationEntity de
    ) {
        Integer effectRow = depreciationService.add(de);
        return effectRow;
    }

    @RequestMapping("del")
    @ResponseBody
    public Integer del (@RequestParam("idArr[]") String[] idArr) {
        return depreciationService.delete(idArr);
    }

}
